package com.example.nacosconsumer.Message;
import com.example.nacosconsumer.pojo.StarInfo;
import com.example.nacosconsumer.service.ForumService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;

@Component
@Slf4j
public class MqReceiver {
    @Resource
    private ForumService forumService;
    /**
     * 接收消息并打印
     * @param message message
     * concurrency min-max 表示并发数，表示有多少个消费者处理队列里的消息 最小-最大数
     */
    @RabbitListener(queues = "Star",concurrency = "5-10")
    public void process(Map<String,String> message) throws Exception{
        // @RabbitListener注解用于监听RabbitMQ，queues指定监听哪个队列
        //更新数据库点赞数
        forumService.Star(message.get("tiezi_ID"), message.get("currentUser"));
        log.info(message.get("tiezi_ID"));

    }

}